#ifndef Net_TcpServerConnection_INCLUDED
#define Net_TcpServerConnection_INCLUDED

#include "runnable.h"

class TcpServerDispatcher;

class TcpServerConnection: public Runnable
{
public:
    TcpServerConnection(int fd):m_fd(fd)
    {}

    virtual ~TcpServerConnection()
    {}

    virtual void run()
    {}
    
    int fd()
    { return m_fd; }
private:
    TcpServerConnection();
    TcpServerConnection(const TcpServerConnection&);
    TcpServerConnection& operator = (const TcpServerConnection&);

private:
    int             m_fd;
    friend class TcpServerDispatcher;
};

class TcpServerConnectionFactory
{
public:
	virtual ~TcpServerConnectionFactory();

	virtual TcpServerConnection* createConnection(int fd) = 0;

protected:
	TcpServerConnectionFactory();

private:
	TcpServerConnectionFactory(const TcpServerConnectionFactory&);
	TcpServerConnectionFactory& operator = (const TcpServerConnectionFactory&);
};


template <class S>
class TcpServerConnectionFactoryImpl: public TcpServerConnectionFactory
{
public:
	TcpServerConnectionFactoryImpl()
	{
	}
	
	~TcpServerConnectionFactoryImpl()
	{
	}
	
	TcpServerConnection* createConnection(int fd)
	{
		return new S(fd);
	}
};

#endif
